<template>
  <div class="mod-user">
    <div style="margin-bottom: 12px;padding-left: 6px">
      <el-button icon="el-icon-plus" type="primary" size="small" @click.stop="add">新增用户</el-button>
    </div>
    <avue-crud ref="crud"
               :page="page"
               :data="dataList"
               :option="tableOption">
      <template slot-scope="scope"
                slot="menu">
        <el-button type="primary"
                   icon="el-icon-edit"
                   size="small"
                   @click.stop="addOrUpdateHandle(scope.row)">编辑</el-button>
        <el-button type="danger" icon="el-icon-delete" size="small" @click.stop="deleteHandle(scope.row.id)">删除</el-button>
      </template>
    </avue-crud>
    <merchant-user-add-or-update ref="merchantAddOrUpdate" @refreshDataList="getDataList"></merchant-user-add-or-update>
  </div>
</template>

<script>
  import { tableOption } from '@/crud/merchant/merchantUserList'
  import merchantUserAddOrUpdate from './merchantUser-add-or-update'
  export default {
    components: {
      merchantUserAddOrUpdate
    },
    data () {
      return {
        merchantId: '',
        dataList: [],
        dataListLoading: false,
        tableOption: tableOption,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
      }
    },

    mounted () {
      console.log(this.$route.query)
      this.merchantId = this.$route.query.id
      this.getDataList()
    },

    methods: {
      // 获取数据列表
      getDataList (page, params) {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/v1/admin/merchant/account/list'),
          method: 'get',
          params: this.$http.adornParams(
            Object.assign(
              {
                current: page == null ? this.page.currentPage : page.currentPage,
                size: page == null ? this.page.pageSize : page.pageSize,
                merchantId: this.merchantId
              },
              params
            )
          )
        }).then(({ data }) => {
          console.log(data)
          this.dataList = data.data.records
          this.page.total = data.data.total
          this.dataListLoading = false
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm(`确定进行删除操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$http({
              url: this.$http.adornUrl('/v1/admin/merchant/account/delete'),
              method: 'post',
              data: this.$http.adornData({id: id})
            }).then(({ data }) => {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList(this.page)
                }
              })
            })
          })
          .catch(() => { })
      },
      // 新增
      add () {
        this.$refs.merchantAddOrUpdate.init(this.merchantId)
      },

      addOrUpdateHandle (row) {
        this.$refs.merchantAddOrUpdate.init(this.merchantId, row)
      }
    }
  }
</script>

<style lang="scss">
  .remain{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    input{
      width: 100px;
    }
  }
  .sumary-list{
    display: flex;
    justify-content: flex-start;
    margin-bottom: 15px;
    div{
      height: 30px;
      padding: 0px 12px;
      line-height: 30px;
      border:solid 1px #009FF1;
      border-radius: 15px;
      margin-right: 10px;
    }
    div:hover{
      color: white;
      background-color: #009FF1;
    }
  }
</style>
